// https://www.luogu.com.cn/problem/P1216

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1003;
int G[N][N];

int main() {
    int r;
    scanf("%d", &r);
    for (int i=1; i<=r; i++) {
        for (int j=1; j<=i; j++) {
            scanf("%d", &G[i][j]);
        }
    }

    for (int i=2; i<=r; i++) {
        for (int j=1; j<=i; j++) {
            G[i][j] += max(G[i-1][j-1], G[i-1][j]);
        }
    }

    printf("%d\n", *max_element(G[r]+1, G[r]+r+1));
    return 0;
}
